package com.twu.biblioteca.util;

import com.twu.biblioteca.entity.Book;
import com.twu.biblioteca.entity.Movie;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: deva
 * Date: 10/1/13
 * Time: 1:11 PM
 * To change this template use File | Settings | File Templates.
 */
public class Formatter {

    public static String formatBooks(ArrayList<Book> books)
    {
        String bookList = "";
        for(Book book : books)
        {
            bookList +=  book.toString() + "\n" ;
        }
        return bookList;
    }

    public static String formatMovies(ArrayList<Movie> movies)
    {
        char tabSpace = '\t';
        String title = formatStringWith30Length("Movie") + tabSpace
                  + "Year" + tabSpace
                + formatStringWith30Length("Director") + tabSpace
                + "Rating";

        String movieList = title + "\n";

        for(Movie movie: movies)
        {
            movieList += "\n" + movie.toString();
        }
        return movieList;
    }

    public static String formatStringWith30Length(String string)
    {
        return String.format("%1$-30s",string);
    }

}
